//
//  HousesViewModel.m
//  YiJuZhangShou2.0
//
//  Created by URANUS on 16/4/8.
//  Copyright © 2016年 Mr.X. All rights reserved.
//

#import "HousesViewModel.h"
#import "HousesModel.h"
#import "HousesView.h"

@implementation HousesViewModel

#pragma mark - Delegate NetworkingBaseManagerAPISuccessCallbackDelegate
- (void)manager:(NetworkingBaseManager *)manager callAPIDidSuccessWithParams:(NSDictionary *)responseParams{
    DDLogInfo(@"查看户型下房屋网络返回数据：%@",[responseParams description]);
    NSArray *dataArray = [responseParams objectForKey:@"data"];
    HousesView *houseView = self.viewObject;
    NSMutableArray *housesArray =  [HousesModel mj_objectArrayWithKeyValuesArray:dataArray];
    for (HousesModel *model in housesArray) {
        model.layoutId = _layoutId;
    }
    houseView.models = housesArray;
}

#pragma mark - Public
- (void)loadRequest{
   HousesView *houseView = self.viewObject;
    self.manager = [NetworkingManagerFactory generateNormalManagerWithRefreshFailureCallBackWithTableView:houseView.tableView];
    RequestGenerator *requestGenerator = [RequestGenerator sharedInstance];
    self.manager.apiName = [requestGenerator generateCommonApiWithName:[NSString stringWithFormat:@"projects/%ld/layouts/%ld/houses",[AppContext sharedInstance].projectId,(long)self.layoutId]];
    self.manager.params = self.postObject;
    self.manager.requestType = HTTP_GET;
    self.manager.successDelegate = self;
    self.manager.validator = self;
    [self.manager loadRequest];
}

@end
